package org.mfw.obj.list
{
	
	import mx.collections.ArrayCollection;
	
	import org.mfw.interfaces.obj.list.ISongList;
	import org.mfw.interfaces.obj.mob.ISong;
	import org.mfw.obj.mob.Song;
	
	/**
	 * Speichert mehrere Lieder in einer Liste
	 * */

	
	public class SongList extends MediaListObject implements ISongList
	{
		public function SongList(object:Object=null)
		{
			super();
			if(object){
				this.getSonglistFromObject(object);
			}
		}
	
	
		protected function getSonglistFromObject(object:Object):void{
			this._elementArray= new Array();
			if(object[0]) {
				for each (var song:Object in object as ArrayCollection) {
					this.elementArray.push(new Song(song));
				}
			 }else if(object.hasOwnProperty("track")){
					this.elementArray.push(new Song(object));
				}		
		}
		
		public function getSongByIndex(index:Number):ISong
		{
			return super.getElementByIndex(index) as ISong;
		}
		
		public function getSongByName(name:String):ISong
		{
			for each (var value:ISong in this._elementArray){
				if (value.name==name){
					return value;
				}
			}
			return null;
		}
		
		public function getSongByID(ID:Number):ISong
		{
			for each (var value:ISong in this._elementArray){
				if (value.ID==ID){
					return value;
				}
			}
			return null;
		}
		
		
		public function get currentSong():ISong
		{
			return super.currentElement as ISong;
		}
		
		
		public function get nextSong():ISong
		{
			return super.nextElement as ISong;
		}
		
		public function get lastSong():ISong
		{
			return super.lastElement as ISong;
		}
		
		public function get prevSong():ISong
		{
			return super.prevElement as ISong;
		}		
	}
}